package com.zcf.service;
import	java.util.stream.Collectors;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zcf.common.json.Body;
import com.zcf.gameController.F_Websocket_s;
import com.zcf.gameController.WebSocketBull;
import com.zcf.mapper.PumpingLogMapper;
import com.zcf.pojo.PumpingLog;
import com.zcf.pojo.User;
import com.zcf.vo.out.LayuiJson;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhaoQi
 * @since 2019-07-29
 */
@Service
public class PumpingLogServiceImpl  {

    @Autowired
    private PumpingLogMapper pumpingLogMapper;

    public LayuiJson toDayPumping(){
        LayuiJson lj=new LayuiJson();
        Calendar calendar1 = Calendar.getInstance();
        calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH),
                0, 0, 0);
        Date beginOfDate = calendar1.getTime();
        Calendar calendar2 = Calendar.getInstance();
        calendar1.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH),
                23, 59, 59);
        Date endOfDate = calendar1.getTime();
        List<PumpingLog> pumpingLogs = pumpingLogMapper.selectByExample(beginOfDate, endOfDate);
        Map<String, Integer> map = new HashMap<String, Integer>();
        List<Map<String, Integer>> list = new ArrayList<Map<String,Integer>>();
        map.put("sum", 0);
        if (pumpingLogs.size()>0){
            List<PumpingLog> collect = pumpingLogs.stream().filter(pumpingLog -> pumpingLog.getPumping() > 0).collect(Collectors.toList());
            int sum = collect.stream().mapToInt(PumpingLog::getPumping).sum();
            map.put("sum", sum);
            list.add(map);
            if(map != null){
                lj.setCode(0);
                lj.setCount(null);
                lj.setData(list);
                lj.setMsg("成功");
                return lj;
            }
        }else {
            list.add(map);
            lj.setCode(0);
            lj.setCount(null);
            lj.setData(list);
            lj.setMsg("成功");
        }

        return lj;
    }
}
